//
//  ReadInfoViewController.m
//  Leisure
//
//  Created by 大展 on 16/4/20.
//  Copyright © 2016年 张展. All rights reserved.
//

#import "ReadInfoViewController.h"

@interface ReadInfoViewController ()

@property (nonatomic, strong)NSMutableDictionary *parameter;
@property (strong, nonatomic) IBOutlet UIWebView *webView;

@end

@implementation ReadInfoViewController

- (NSMutableDictionary *)parameter {

    if (!_parameter) {

        _parameter = [NSMutableDictionary dictionaryWithObjectsAndKeys:self.contentid,@"contentid", nil];
    }
    return _parameter;
}
- (void)viewDidLoad {
    [super viewDidLoad];

    [self fetchSourceDataWithUrl:kReadInfoUrl parameter:self.parameter];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)fetchSourceDataWithUrl:(NSString *)url parameter:(NSMutableDictionary *)parameter {


    // 初始化AFN请求工具
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    // 设置请求类型
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    // 开始请求
    [manager POST:url parameters:parameter progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:(NSJSONReadingAllowFragments) error:nil];

        NSString *htmlStr = dic[@"data"][@"html"];


        self.webView.scalesPageToFit = YES;

        // webView加载str
        [self.webView loadHTMLString:htmlStr baseURL:nil];
        

        



    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
